using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using CPlatePrintSys.Domain.Models;

namespace CPlatePrintSys.Win.ViewModels
{
    /// <summary>
    /// 合并测试数据生成器
    /// </summary>
    public static class MergeTestDataGenerator
    {
        /// <summary>
        /// 生成包含合并信息的测试数据
        /// </summary>
        public static ObservableCollection<PlateAnnotationInfo> GenerateMergeTestData()
        {
            var testData = new ObservableCollection<PlateAnnotationInfo>();
            var random = new Random();

            // 生成10条测试数据
            for (int i = 1; i <= 10; i++)
            {
                var info = new PlateAnnotationInfo
                {
                    Id = i,
                    MotherShipNo = "N1159",
                    StreamShipNo = "N1159",
                    LotNo = (i <= 3) ? "A05A" : (i <= 6) ? "A05B" : "A05C",
                    PlateNo = $"A{i:D3}",
                    Sequence = (i <= 3) ? "7PA" : (i <= 6) ? "7PB" : "3PS",
                    CNO = $"A{i:D3}7PA{i:D3}",
                    DesignSpecCls = "A",
                    DesignSpecThickness = 13 + (i % 3) * 2,
                    DesignSpecLength = 2000 + i * 100,
                    DesignSpecWidth = 1000 + i * 50,
                    SheetConsistentNo = $"A{i:D3}7PA{i:D3}",
                    SheetSpecCls = "A",
                    SheetSpecThickness = 13 + (i % 3) * 2,
                    SheetSpecLength = 2000 + i * 100,
                    SheetSpecWidth = 1000 + i * 50,
                    LayoutMean = LayoutMean.Unprocessed,
                    MergedInfo = "",
                    LayoutInfo = "",
                    PlanUsedDate = DateTime.Now.AddDays(i),
                    IsAnnotationGenerated = false,
                    DesignDrawingPath = $"C:\\Test\\Drawing_{i}.dxf",
                    SourceType = SourceType.KMACS
                };

                // 为第3、4、5条记录设置合并信息
                if (i >= 3 && i <= 5)
                {
                    info.LayoutMean = LayoutMean.MergedLayout;
                    info.LayoutInfo = "{\"LayoutMean\":\"2\",\"Merged\":{\"PartLayouts\":[{\"SheetConsistentNo\":\"A0037PA003\"},{\"SheetConsistentNo\":\"A0047PA004\"},{\"SheetConsistentNo\":\"A0057PA005\"}]}}";
                    info.MergedInfo = "A0037PA003,A0047PA004,A0057PA005";
                    
                    // 设置不同的值用于测试合并显示
                    if (i == 3)
                    {
                        info.StreamShipNo = "65";
                        info.CNO = "N29A7PA005";
                        info.DesignSpecWidth = 2298;
                        info.DesignSpecLength = 1361;
                        info.SheetConsistentNo = "A05B7PB001";
                        info.SheetSpecWidth = 2300;
                    }
                    else if (i == 4)
                    {
                        info.StreamShipNo = "61";
                        info.CNO = "A05B7PB002";
                        info.DesignSpecWidth = 3320;
                        info.DesignSpecLength = 6117;
                        info.SheetConsistentNo = "A05B7PB002";
                        info.SheetSpecWidth = 6117;
                    }
                    else if (i == 5)
                    {
                        info.StreamShipNo = "63";
                        info.CNO = "N29A7PA007";
                        info.DesignSpecWidth = 1500;
                        info.DesignSpecLength = 8000;
                        info.SheetConsistentNo = "A05B7PB003";
                        info.SheetSpecWidth = 1800;
                    }
                }

                testData.Add(info);
            }

            return testData;
        }

        /// <summary>
        /// 生成合并测试的ViewModel数据
        /// </summary>
        public static ObservableCollection<PlateAnnotationInfoViewModel> GenerateMergeTestViewModels()
        {
            var testData = GenerateMergeTestData();
            return PlateAnnotationInfoViewModel.CreateFromList(testData);
        }
    }
}
